1 package uk.ac.roe.antigen.dialogs;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.FlowLayout;
6 import java.awt.GridLayout;
7 import java.awt.Point;
8 import java.awt.Toolkit;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11
12 import javax.swing.BorderFactory;
13 import javax.swing.BoxLayout;
14 import javax.swing.ImageIcon;
15 import javax.swing.JButton;
16 import javax.swing.JFrame;
17 import javax.swing.JPanel;
18 import javax.swing.JTextArea;
19 import javax.swing.JTextField;
20 import javax.swing.border.BevelBorder;
21 import javax.swing.border.TitledBorder;
22
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.input.InputHandler;
25 import org.apache.tools.ant.input.InputRequest;
26 import org.apache.tools.ant.taskdefs.optional.net.SetProxy;
27
28 import uk.ac.roe.antigen.utils.Config;
29
30
31 public class TextPropertyInputHandler extends javax.swing.JDialog implements InputHandler {
32 private JTextField propertyValueTxt;
33 private JPanel jPanel1;
34 private JPanel jPanel4;
35 private JTextArea propertyNameLbl;
36 private JPanel jPanel3;
37 private JButton okBtn;
38 private JPanel jPanel2;
39
40 /***
41 * Auto-generated main method to display this JDialog
42 */
43 public static void main(String[] args) {
44 JFrame frame = new JFrame();
45 frame.setVisible(true);
46 TextPropertyInputHandler inst = new TextPropertyInputHandler(frame);
47 inst.setVisible(true);
48 }
49
50 public TextPropertyInputHandler(JFrame frame) {
51 super(frame);
52 initGUI();
53 }
54
55 private void initGUI() {
56 try {
57 setSize(600, 150);
58 setUndecorated(true);
59 {
60 jPanel2 = new JPanel();
61 this.getContentPane().add(jPanel2, BorderLayout.CENTER);
62 BorderLayout jPanel2Layout = new BorderLayout();
63 jPanel2.setLayout(jPanel2Layout);
64 {
65 jPanel3 = new JPanel();
66 jPanel2.add(jPanel3, BorderLayout.SOUTH);
67 FlowLayout jPanel3Layout = new FlowLayout();
68 jPanel3.setOpaque(false);
69 jPanel3.setLayout(jPanel3Layout);
70 {
71 okBtn = new JButton();
72 jPanel3.add(okBtn);
73 okBtn.setText("Next");
74 okBtn.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/rightarrow.png")));
75 okBtn.addActionListener(new ActionListener() {
76 public void actionPerformed(ActionEvent evt) {
77 okPressed = true;
78 }
79 });
80 }
81 }
82 {
83 jPanel4 = new JPanel();
84 BoxLayout jPanel4Layout = new BoxLayout(jPanel4,BoxLayout.PAGE_AXIS);
85 String borderTitle = Config.getProperty("antigen.dialog.bordertitle","antigen");
86 jPanel4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(BevelBorder.RAISED, null, null), borderTitle, TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Eurostile",0,12), new java.awt.Color(0,0,255)));
87 jPanel4.setLayout(jPanel4Layout);
88 jPanel2.add(jPanel4, BorderLayout.CENTER);
89 {
90 propertyNameLbl = new JTextArea();
91 jPanel4.add(propertyNameLbl);
92 propertyNameLbl.setLineWrap(true);
93 propertyNameLbl.setWrapStyleWord(true);
94 propertyNameLbl
95 .setText("message very long very long very long very long very long very long very long very long very long very long very long very long very long very long very long very long very long");
96 propertyNameLbl.setFont(new java.awt.Font(
97 "Dialoginput",
98 0,
99 12));
100 propertyNameLbl.setOpaque(false);
101 propertyNameLbl.setEditable(false);
102 propertyNameLbl.setAutoscrolls(true);
103 }
104 {
105 jPanel1 = new JPanel();
106 GridLayout jPanel1Layout = new GridLayout(1, 1);
107 jPanel1.setLayout(jPanel1Layout);
108 jPanel4.add(jPanel1);
109 {
110 propertyValueTxt = new JTextField();
111 jPanel1.add(propertyValueTxt);
112 propertyValueTxt
113 .setText("01234567890123456789012345678901234567890123401234567890123456890123456789");
114 propertyValueTxt.setBorder(BorderFactory
115 .createBevelBorder(
116 BevelBorder.LOWERED,
117 null,
118 null,
119 null,
120 null));
121 propertyValueTxt
122 .addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent evt) {
124 okPressed = true;
125 }
126 });
127 }
128 }
129 }
130 }
131 } catch (Exception e) {
132 e.printStackTrace();
133 }
134 this.setLocation(getDialogLocation().width, getDialogLocation().height);
135 }
136
137 boolean okPressed = false;
138
139
140
141 public void handleInput(InputRequest arg0) throws BuildException {
142 okPressed = false;
143 this.setVisible(true);
144 propertyNameLbl.setText(arg0.getPrompt().trim());
145 propertyValueTxt.setText(arg0.getDefault());
146 while (!okPressed) {
147 try {
148 Thread.sleep(100);
149 } catch (InterruptedException ie) {}
150 }
151 arg0.setInput(propertyValueTxt.getText());
152 this.setVisible(false);
153 this.dispose();
154 }
155
156 /***
157 * Calculates the desired location of the dialog on the screen.
158 * By default it is in the center of the screen.
159 *
160 * @return the desired location of the dialog on the screen
161 */
162 private Dimension getDialogLocation() {
163
164 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
165 Dimension dlgInputDim = this.getSize();
166 Dimension splashDim = getOwner().getSize();
167 Point splashLoc = getOwner().getLocationOnScreen();
168
169 int dlgInputX = (int)
170 ((screenDim.getWidth() - dlgInputDim.getWidth()) / 2);
171 int dlgInputY = (int)
172 splashLoc.y+splashDim.height;
173 return new Dimension(dlgInputX, dlgInputY);
174 }
175
176 }